package com.asiainfo.work.service.master.impl;

import com.asiainfo.work.dao.master.MergeDao;
import com.asiainfo.work.entity.UserGroup;
import com.asiainfo.work.entity.UserMergeCode;
import com.asiainfo.work.request.merge.MergeRequest;
import com.asiainfo.work.service.master.MergeService;
import com.asiainfo.work.utils.BaseResponse;
import com.asiainfo.work.utils.PageResponse;
import com.asiainfo.work.utils.PageResponseUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.gson.Gson;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author: bf
 * @date: 2021/1/4-12:52
 */
@Service
@Slf4j
public class MergeServiceImpl extends ServiceImpl<MergeDao, UserMergeCode> implements MergeService {

    @Autowired
    MergeDao masterDao;

    /**
     * 批量保存 UserMergeCode对象
     * @param list UserMergeCodeList
     */
    @Override
    public void batchInsert(List<UserMergeCode> list) {
        masterDao.batchInsert(list);
    }

    /**
     * 查询合并代码信息
     * @param mergeRequest  请求参数
     */
    @Override
    public BaseResponse<PageResponse<UserMergeCode>> query(MergeRequest mergeRequest) {
        log.info("查询合并代码信息, 参数 mergeRequest={} ",  new Gson().toJson(mergeRequest));
        IPage<UserMergeCode> plusPage = new Page<>(mergeRequest.getPage(),
                mergeRequest.getSize());
        String endTime = mergeRequest.getEndTime();
        String startTime = mergeRequest.getStartTime();
        List<String> accountList = mergeRequest.getAccountList();
        List<UserMergeCode> resultList = masterDao.query(startTime, endTime, accountList, plusPage);
        plusPage.setRecords(resultList);
        return BaseResponse.success(PageResponseUtil.getPageResponse(plusPage));
    }

    /**
     * 查询所有用户信息
     * @return 用户信息
     */
    @Override
    public BaseResponse<List<UserGroup>> queryUserList() {
        List<UserGroup> resultList = masterDao.queryUserList();
        return BaseResponse.success(resultList);
    }

}
